//对手方回购
import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'manRepurchaseCounterpartyM',
  state: {},
  effects: {
    //查询列表
    *queryRepurchaseCounterpartyList({ payload, callback }, { call, put }) {
      const res = yield call(api.manRepurchaseCounterparty.queryRepurchaseCounterpartyList, payload);

      if (res && res.code == 0) {
        callback(res.data || {});
      } else {
        callback();
        message.error(res ? res.msg || '查询列表失败！' : '查询列表失败！');
      }
    },
    //保存回购对手方
    *saveCounterparty({ payload, callback }, { call, put }) {
      const res = yield call(api.manRepurchaseCounterparty.saveCounterparty, payload);
      if (res && res.code == 0) {
        callback(res);
        message.success(res.msg || '操作成功！');
      } else {
        message.error(res ? res.msg || '补充信息失败！' : '补充信息失败！');
      }
    },
    //批量确认
    *batchConfirm({ payload, callback }, { call, put }) {
      const res = yield call(api.manRepurchaseCounterparty.batchConfirm, payload);
      if (res && res.code == 0) {
        callback('success');
      } else {
        message.error(res ? res.msg || '批量确认失败！' : '批量确认失败！');
      }
    },
    //删除
    *deleteById({ payload, callback }, { call, put }) {
      const res = yield call(api.manRepurchaseCounterparty.deleteById, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res?.msg || '删除失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
